//笔试强训：岛屿数量
//0代表海洋，1代表陆地，数陆地数量

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 判断岛屿数量
     * @param grid char字符型vector<vector<>> 
     * @return int整型
     */
    void delLand(vector<vector<char>>& grid, int i, int j, int m, int n)
    {
        if(i < 0 || i >= m || j < 0 || j >= n || grid[i][j] == '0')
            return;
        grid[i][j] = '0';
        delLand(grid, i - 1, j, m, n);
        delLand(grid, i + 1, j, m, n);
        delLand(grid, i, j - 1, m, n);
        delLand(grid, i, j + 1, m, n);
    }

    int solve(vector<vector<char> >& grid) {
        // write code here
        int sum = 0, m = grid.size(), n = grid[0].size();
        for(int i = 0; i < m; ++i)
        {
            for(int j = 0; j < n; ++j)
            {
                if(grid[i][j] == '1')
                {
                    sum += 1;
                    delLand(grid, i, j, m, n);
                }
            }
        }
        return sum;
    }
};